﻿package com.iflytek.elpmobile.utils;


public class PackageUtils {
	public static final String TAG = PackageUtils.class.getSimpleName();

	public static class FilePosition {
		private int mOffset = 0;
		private int mSize = 0;

		public FilePosition(int offset, int size) {
			mOffset = offset;
			mSize = size;
		}

		public int getOffset() {
			return mOffset;
		}

		public int getSize() {
			return mSize;
		}
	};

	public final static String getMd5(String key) {
		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'a', 'b', 'c', 'd', 'e', 'f' };
		try {
			byte[] md = CryptoUtils.getMd5(key);
			char str[] = new char[md.length * 2];
			int k = 0;
			for (int i = 0; i < md.length; i++) {
				byte b = md[i];
				// 将每个(int)b进行双字节加密
				str[k++] = hexDigits[b >> 4 & 0xf]; // 取字节中高 4 位的数字转换,
													// >>> 为逻辑右移，将符号位一起右移
				str[k++] = hexDigits[b & 0xf]; // 取字节中低 4 位的数字转换
			}
			return new String(str);
		} catch (Exception e) {
			return null;
		}
	}



	
	public static int checkSum(String data) {
		if (StringUtils.isEmpty(data))
			return 0;
		
		byte [] buffer = data.getBytes();
		return jni_checkSum(buffer);
	}



	private static native int 		jni_checkSum(byte[] data);
	

	public  static native String  jni_CryptoRc4(String data, String pass);

	public  static native int     jni_getAudioLevel(byte[] data, int size);
	
	static {
		try{
			System.loadLibrary("PackageUtils");
		}catch(Error e){
			Logger.e("PackageUtils", "load libPackageUtils so error:"+e.toString());
		}
		}
}
